package com.ruoyi.web.controller.memberCoupon;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProductPassCardRules;
import com.ruoyi.system.service.IProductPassCardRulesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品次卡规则 Controller
 *
 * @author ruoyi
 * @date 2025-05-23
 */
@Api(tags="商品次卡规则")
@RestController
@RequestMapping("/system/productPassCardRules")
public class ProductPassCardRulesController extends BaseController
{
    @Autowired
    private IProductPassCardRulesService productPassCardRulesService;

    /**
     * 通过门店名称查询商品次卡规则列表
     */
    @ApiOperation("通过门店名称查询商品次卡规则列表")
    @PreAuthorize("@ss.hasPermi('system:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<ProductPassCardRules> list = productPassCardRulesService.selectProductPassCardRulesListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出商品次卡规则列表
     */
    @ApiOperation("导出商品次卡规则列表")
    @PreAuthorize("@ss.hasPermi('system:rules:export')")
    @Log(title = "商品次卡规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<ProductPassCardRules> list = productPassCardRulesService.selectProductPassCardRulesListByName(storeName);
        ExcelUtil<ProductPassCardRules> util = new ExcelUtil<ProductPassCardRules>(ProductPassCardRules.class);
        util.exportExcel(response, list, "商品次卡规则数据");
    }

    /**
     * 通过id获取商品次卡规则详细信息
     */
    @ApiOperation("通过id获取商品次卡规则详细信息")
    @PreAuthorize("@ss.hasPermi('system:rules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productPassCardRulesService.selectProductPassCardRulesById(id));
    }

    /**
     * 新增商品次卡规则
     */
    @ApiOperation("新增商品次卡规则")
    @PreAuthorize("@ss.hasPermi('system:rules:add')")
    @Log(title = "商品次卡规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductPassCardRules productPassCardRules)
    {
        return toAjax(productPassCardRulesService.insertProductPassCardRules(productPassCardRules));
    }

    /**
     * 修改商品次卡规则
     */
    @ApiOperation("修改商品次卡规则")
    @PreAuthorize("@ss.hasPermi('system:rules:edit')")
    @Log(title = "商品次卡规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPassCardRules productPassCardRules)
    {
        return toAjax(productPassCardRulesService.updateProductPassCardRules(productPassCardRules));
    }

    /**
     * 通过id批量删除商品次卡规则信息
     */
    @ApiOperation("通过id批量删除商品次卡规则信息")
    @PreAuthorize("@ss.hasPermi('system:rules:remove')")
    @Log(title = "商品次卡规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productPassCardRulesService.deleteProductPassCardRulesByIds(ids));
    }
}
